//封装Axios
import axios from 'axios';

import { BASE_URL, TIMEOUT } from './config';
/* 封装axios */
const instance = axios.create({
  baseURL: BASE_URL,
  timeout: TIMEOUT,
});

instance.interceptors.request.use(
  (config) => {
    /* 查询用户token */
    const token = window.localStorage.getItem('token');
    if (token) {
      config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
  },
  (err) => {
    return err;
  },
);
instance.interceptors.response.use(
  (res) => {
    return res.data;
  },
  (err) => {
    return err;
  },
);

export default instance;
